unit unit_frmChildBaseForm;

interface

uses
  Windows, Classes, SysUtils, Controls, Messages, Forms, StdCtrls, ExtCtrls,
  DBGrids, Grids, DBCtrls, DBGridEh,
  TB2Item, ImgList,
  ActnList, TB2Dock, TB2Toolbar, cxLookAndFeels, dxSkinsForm,

  unit_frmBaseForm;

type
  TfrmChildBaseForm = class(TFrmBaseForm)
    aclChild: TActionList;
    actClose: TAction;
    img32: TImageList;
    imgToolBar: TTBImageList;
    imgToolBar16: TTBImageList;
    img16: TImageList;
    timAfterFromCreate: TTimer;
    tbdChildFormDock: TTBDock;
    tbrChildToolBar: TTBToolbar;
    tbiClose: TTBItem;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure actCloseExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FFdName, FSortOrder: string;
    procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  protected
    function GetTitle(Sender: TCustomGrid): string; virtual;
    function GetDwmc(Sender: TCustomGrid): string; virtual;
    function GetRq(Sender: TCustomGrid): string; virtual;
    procedure SetLayout(Ctrl: TWinControl);
  public
    { Public declarations }
    FFormPoint:TfrmChildBaseForm;
    procedure WMMDIActivate(var Message: TWMMDIActivate); message WM_MDIActivate;
   // procedure WMEraseBKGnd(var Message: TWMEraseBKGnd); message WM_ERASEBKGND;
  end;

var
  frmChildBaseForm: TfrmChildBaseForm;

implementation

uses unit_frmMainBaseForm, uGlobalFun;

type
  TFMainBaseAccess = class(TFrmMainBaseForm)
  end;

{$R *.dfm}

procedure TfrmChildBaseForm.FormCreate(Sender: TObject);
begin
  inherited;
  timAfterFromCreate.Enabled := False;

  if Self.FormStyle = fsMDIChild then
  begin
    BorderStyle := bsSingle;
    BorderIcons := [];
  end;

  FixComponment(Self);
end;

procedure TfrmChildBaseForm.FormActivate(Sender: TObject);
begin
  inherited;
  if Self.FormStyle = fsMDIChild then
    if (Application.MainForm <> nil) and (Application.MainForm is TFrmMainBaseForm) then
      TFMainBaseAccess(Application.MainForm).ActiveFormTab(Self);
end;

procedure TfrmChildBaseForm.FormDestroy(Sender: TObject);
begin
  inherited;
  if Self.FormStyle = fsMDIChild then
    if (Application.MainForm <> nil) and (Application.MainForm is TFrmMainBaseForm) then
      TFMainBaseAccess(Application.MainForm).DelFormTab(Self);
end;

procedure TfrmChildBaseForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  IsFound: Boolean;
  I: Integer;
begin
  inherited;
 { case Key of
    VK_RETURN:
      if not (ActiveControl is TDBGrid) and not (ActiveControl is TDBMemo) then
      begin
        SelectNext(ActiveControl, True, True);
      end
      else if ActiveControl is TDBGrid then
      begin
        if TDBGrid(ActiveControl).SelectedIndex < TDBGrid(ActiveControl).FieldCount - 1 then
        begin
          IsFound := False;
          for I := TDBGrid(ActiveControl).SelectedIndex + 1 to TDBGrid(ActiveControl).FieldCount - 1 do
          begin
            if not TDBGrid(ActiveControl).Columns[I].ReadOnly then
            begin
              TDBGrid(ActiveControl).SelectedIndex := I;
              IsFound := True;
              Break;
            end;
          end;
          if (not IsFound) and (not TDBGrid(ActiveControl).DataSource.DataSet.Eof) then
          begin
            TDBGrid(ActiveControl).DataSource.DataSet.Next;
            for I := 0 to TDBGrid(ActiveControl).FieldCount - 1 do
              if not TDBGrid(ActiveControl).Columns[I].ReadOnly then
              begin
                TDBGrid(ActiveControl).SelectedIndex := I;
                Break;
              end;
          end;
        end
        else if not TDBGrid(ActiveControl).DataSource.DataSet.Eof then
        begin
          TDBGrid(ActiveControl).DataSource.DataSet.Next;
          for I := 0 to TDBGrid(ActiveControl).FieldCount - 1 do
            if not TDBGrid(ActiveControl).Columns[I].ReadOnly then
            begin
              TDBGrid(ActiveControl).SelectedIndex := I;
              Break;
            end;
        end;
      end;
    Ord('P'): if (Shift = [ssCtrl]) then
      begin
        if (ActiveControl is TDBGridEh) then
        begin
          Key := 0;
        end
      end;
  end; }

end;

procedure TfrmChildBaseForm.FormShow(Sender: TObject);
begin
  inherited;
  SetLayout(Self)
end;

procedure TfrmChildBaseForm.CMTextChanged(var Message: TMessage);
begin
  if Self.FormStyle = fsMDIChild then
    if (Application.MainForm <> nil) and (Application.MainForm is TFrmMainBaseForm) then
      TFMainBaseAccess(Application.MainForm).ChangeFormTabTitle(Self);
end;

function TfrmChildBaseForm.GetDwmc(Sender: TCustomGrid): string;
begin
  Result := EmptyStr;
end;

function TfrmChildBaseForm.GetRq(Sender: TCustomGrid): string;
begin
  Result := EmptyStr;
end;

function TfrmChildBaseForm.GetTitle(Sender: TCustomGrid): string;
begin
  Result := Self.Caption;
end;

procedure TfrmChildBaseForm.SetLayout(Ctrl: TWinControl);
var
  K: Integer;
begin
  if Ctrl is TDBGridEh then
    with TDBGridEh(Ctrl) do
    begin
      if TDBGridEh(Ctrl).RowHeight = 0 then
      begin
        TDBGridEh(Ctrl).RowHeight := 20;
        for K := 0 to Columns.Count - 1 do
          Columns[K].Layout := tlCenter
      end
    end;
  for K := 0 to Ctrl.ControlCount - 1 do
    if Ctrl.Controls[K] is TWinControl then
      SetLayout(Ctrl.Controls[K] as TWinControl)
end;

procedure TfrmChildBaseForm.WMMDIActivate(var Message: TWMMDIActivate);
begin
  inherited;
  if (Self.FormStyle = fsMDIChild) and (Handle = Message.ActiveWnd) then
  begin
    ShowWindow(Message.ActiveWnd, SW_MAXIMIZE);
  end;
end;

procedure TfrmChildBaseForm.actCloseExecute(Sender: TObject);
begin
  inherited;
  close;
end;

procedure TfrmChildBaseForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

//procedure TfrmChildBaseForm.WMEraseBKGnd(var Message: TWMEraseBKGnd);
//begin
//  Message.Result := 1;
//end;



end.

